<?php
declare(strict_types=1);

namespace App\Models\Image;

use App\Models\BaseModel;
use App\Models\User\Image\SeriesModel;
use Illuminate\Database\Eloquent\Relations\BelongsTo;

class Image extends BaseModel
{
    protected $table = "image";

    protected $fillable = [
        "uid",
        "user_uid",
        "author_uid",
        "series_uid",
        "item_count",
        "url",
        "path",
        "title",
        "download",
        "collect",
        "created_at",
        "updated_at",
        "is_show",
        "device_type",
        "content",
        "is_recommend",
        "subject_uid",
        "sort",
        "audit_msg",
    ];

    protected $casts = [
        "uid" => "string",
        "series_uid" => "string",
    ];

    public function getContentAttribute($key): string
    {
        return !empty($key) ? $key : "";
    }

    public function series(): BelongsTo
    {
        return $this->belongsTo(SeriesModel::class, "series_uid", "uid");
    }

    /**
     * 壁纸专题
     * @return BelongsTo
     */
    public function subject(): BelongsTo
    {
        return $this->belongsTo(ImageSubject::class, "subject_uid", "uid");
    }
}
